using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace OhioState.Graphics.Proxy
{
    /// <summary>
    /// This class represents a two-dimensional transfer function.
    /// </summary>
    public class TransferFunction2D : TexImage, IPreviewable
    {
        private Bitmap textureBitmap;

        public Bitmap TextureBitmap
        {
            get { return textureBitmap; }
            set { textureBitmap = value; }
        }

        /// <summary>
        /// Create a new two-dimensional transfer function.
        /// </summary>
        /// <param name="name">The name of the transfer function.</param>
        public TransferFunction2D(String name)
            : base(name)//, 256, 256)
        {
            this.Width = 256;
            this.Height = 256;

            TexelFormat texFormat = this.TexelType;
            texFormat.Format = ImageFormat.RGBA;
            texFormat.Type = ByteFormat.BYTE;
            this.TexelType = texFormat;
            textureBitmap = new Bitmap(256, 256, PixelFormat.Format32bppArgb);
        }

        public override void GetTexture(out byte[] texels)
        {
            texels = new byte[256 * 256 * 4];
            //debug!
            textureBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            //
            for (int j = 0; j < 256; j++)
            {
                for (int i = 0; i < 256; i++)
                {
                    Color texel = textureBitmap.GetPixel(i, j);
                    texels[4 * 256 * j + 4 * i + 0] = texel.R;
                    texels[4 * 256 * j + 4 * i + 1] = texel.G;
                    texels[4 * 256 * j + 4 * i + 2] = texel.B;
                    texels[4 * 256 * j + 4 * i + 3] = texel.A;
                }
            }

        }

        public void Preview(Bitmap bitmap)
        {
        }
    }
}
